package cn.com.dcsgo.controller;


import cn.com.dcsgo.model.product.Category;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.CategoryService;
import cn.com.dcsgo.vo.product.CategoryQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/*
接口路径及参数参考前端文件：
uu-preferred-front-end/uuyx-admin/src/api/product/category.js
 */

/**
 * <p>
 * 商品三级分类 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-07
 */
@Api(tags = "商品分类")
@RequiredArgsConstructor
@RestController
@RequestMapping("admin/product/category")
public class CategoryController {
    private final CategoryService categoryService;

    @ApiOperation("分页查询分类信息")
    @GetMapping("{page}/{size}")
    public Result<IPage<Category>> getPageList(@PathVariable Long page,
                                               @PathVariable Integer size,
                                               CategoryQueryVo categoryQueryVo) {
        Page<Category> pageParam = new Page<>(page, size);
        IPage<Category> result = categoryService.selectCategoryPage(pageParam, categoryQueryVo);
        return Result.ok(result);
    }

    @ApiOperation("通过id获取分类")
    @GetMapping("get/{id}")
    public Result<Category> getById(@PathVariable Long id) {
        return Result.ok(categoryService.getById(id));
    }

    @ApiOperation("添加分类")
    @PostMapping("save")
    public Result<Serializable> save(@RequestBody Category category) {
        categoryService.save(category);
        return Result.ok(null);
    }

    @ApiOperation("更新分类")
    @PutMapping("update")
    public Result<Serializable> updateById(@RequestBody Category category) {
        categoryService.updateById(category);
        return Result.ok(null);
    }

    @ApiOperation("通过id删除分类")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> removeById(@PathVariable Long id) {
        categoryService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation("通过id批量删除分类")
    @DeleteMapping("batchRemove")
    public Result<Serializable> removeBathByIds(@RequestBody List<Long> idList) {
        categoryService.removeByIds(idList);
        return Result.ok(null);
    }

    @ApiOperation("获取所有分类")
    @GetMapping("findAllList")
    public Result<List<Category>> findAllList() {
        return Result.ok(categoryService.list());
    }
}

